﻿var _count=0; 
function onsucc(result)
{
    if (result!=null)
    {
        _count=result[1].RecordCount;
       RendComList(result[0],"CommentList");
    }
    else
    {
       
        $get("MessagesBox").style.display='';
        $get("MessageImg").src = MessageImageF;
        $get("MessageText").innerHTML = MessageTextF;
    }      
    showProgressBar(false);
}

//替换小黑板上面的信息
function RendComList(list,divID)
{
    var domDiv1 = $get(divID);   
    if(domDiv1!=null)
    {
        if(Sys.UI.DomElement.containsCssClass(domDiv1, "DisplayNone"))
        {
           Sys.UI.DomElement.removeCssClass(domDiv1, "DisplayNone");
        }
        if($get("CommentTemplate")==null) return;
        var item= $get("CommentTemplate").innerHTML;
        var listBuilder = new Sys.StringBuilder();
        for (var index = 0; index < list.length; ++index) 
        {
            var obj = list[index];
            var tmp = item.replace(/\$Avatar\$/gi,"<img src=\""+(obj.avatar==""?"/Images/No_pic.gif":obj.avatar)+"\"/>");
            tmp = tmp.replace(/\$NickName\$/gi,obj.nickname);
            tmp = tmp.replace(/\$userFrom\$/gi,obj.userFrom);
            tmp = tmp.replace(/\$content\$/gi,EncodeMessage(obj.content));
            tmp = tmp.replace(/\$tcm2Id\$/gi,obj.tcm2Id);
            tmp = tmp.replace(/\$postby\$/gi,C0090.replace("{0}","<a href='/"+obj.userFrom+".htm'>"+obj.nickname+"</a>"));            
            tmp = tmp.replace(/\$CreateDate\$/gi,GetFormatDate(gDateFormat,gStrDate2,obj.DiffDate));           
            listBuilder.append(tmp);
        }
        domDiv1.innerHTML = listBuilder.toString();       
         $("View").innerHTML="("+_count+")";
   }
   $EndMessageBox$();
}
//删除选中的留言
function delComm(id)
{
    if(__P_M=="")
    {
        top.location = "/user/login.htm?IsShow=1&ReturnUrl="+top.location.href;
        return;
    }
    showProgressBar(false,true);
    $("$divIput$").style.display = "none";
    var title = C1008;
    var body="<div class='Popup_button'><input type='button' value='"+C0069+"' id='addOkButton' class='button' onclick=\"CommDelete('"+id+"')\" />&nbsp;&nbsp;<input type='button' value='"+gCancel+"' id='addCancelButton' class='buttong' onclick='webFailure()'/></div>";
    var obj = {}  
    $ShowMessageBox$(title,body,obj,webFailure,300);
}
function CommDelete(id)
{
    WebServices.My.DeleteGetComment(1,10,id,onsucc);
}
function webFailure()
{
    $EndMessageBox$();
}
function bind(obj,method)
{
	var args=[];
	for(var ii=2;ii<arguments.length;ii++){args.push(arguments[ii]);}
	return function()
	{
		var _obj=obj||this;
		var _args=args.slice();
		for(var jj=0;jj<arguments.length;jj++){_args.push(arguments[jj]);}
		if(typeof(method)=="string")
		{
			if(_obj[method])
			{
				return _obj[method].apply(_obj,_args);
			}
		}
		else
		{
			return method.apply(_obj,_args);
		}
	}
}
Function.prototype.bind=function(context)
{
	var argv=[arguments[0],this];
	var argc=arguments.length;
	for(var ii=1;ii<argc;ii++){argv.push(arguments[ii]);}
	return bind.apply(null,argv);
}
var KEYS={BACKSPACE:8,TAB:9,RETURN:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,DELETE:46};
function ge(objID)
{
	return document.getElementById(objID);
}
function show()
{
	for(var i=0;i<arguments.length;i++)
	{
		var element=ge(arguments[i]);
		if(element&&element.style)element.style.display='';
	}
	return false;
}
function hide()
{
	for(var i=0;i<arguments.length;i++)
	{
		var element=ge(arguments[i]);
		if(element&&element.style)element.style.display='none';
	}
	return false;
}
status_editor=
{
	active:false,
	menu_active:false,
	status_text:'',
	status_blur:false,
	status_reblur:false,
	setup:function(initial_status)
	{
		this.status_text=initial_status;
	},
	reset:function()
	{
		ge('edit_status_text').value='';
		return false;
	},
	show:function()
	{
		if(!this.active)
		{
			hide('profile_status');
			hide('profile_empty_status');
			this.hide_menu();
			show('status_editor');
			if(ge('status_text').firstChild){this.status_text=ge('status_text').firstChild.nodeValue;}
			ge('edit_status_text').value=this.status_text;
			ge('edit_status_text').focus();
			ge('edit_status_text').select();
			this.status_blur=true;
			this.active=true;
		}
		else
		{
			ge('edit_status_text').focus();
		}
		return false;
	},
	hide:function()
	{
		if(!this.active){return;}
		this.active=false;
		this.status_blur=false;
		hide('status_editor');
		show((this.status_text!='')?'profile_status':'profile_empty_status');
		return false;
	},
	toggle_menu:function(event)
	{
		if(window.ActiveXObject) this.status_reblur=true;
		if(this.menu_active){return this.hide_menu();}else{return this.show_menu();}
	},
	show_menu:function(event)
	{
		this.menu_active=true;
		ge('edit_status_toggle').style.backgroundImage='url(/images/status_on.gif)';
		ge('edit_status_toggle').style.backgroundColor='#fff';
		ge('edit_status_select').style.display='block';
		return false;
	},
	hide_menu:function()
	{
		this.menu_active=false;
		ge('edit_status_toggle').style.backgroundImage='url(/images/status_off.gif)';
		ge('edit_status_toggle').style.backgroundColor='#D8DFEA';
		hide('edit_status_select');return false;
	},
	status_select:function(text)
	{
		if(window.ActiveXObject) this.status_reblur=true;
		this.hide_menu();
		ge('edit_status_text').value=text;
		ge('edit_status_text').focus();
		ge('edit_status_text').select();
	},
	blur:function()
	{
		if(this.status_reblur)
		{
			ge('edit_status_text').focus();
			this.status_reblur=false;return false;
		}
		if(this.status_blur)
		{
			if(ge('edit_status_text').value!=this.status_text)
			{
				this.submit_status_set(ge('edit_status_text').value);
			}
			else{this.hide();}
		}
		return true;
	},
	status_set:function(status)
	{
		this.status_text=status||'';
		this.reset();this.hide();
		if(status!=null&&status!='')
		{
			ge('status_text').innerHTML=this.status_text;
			//ge('status_time').innerHTML='Updated&nbsp;just&nbsp;a&nbsp;moment&nbsp;ago';
		}
		else
		{
			ge('status_text').innerHTML='Error Updating Status';
		}
	},
	submit_status_set:function(status)
	{
		if(status==null||status=='')return;
		requestByGET(status,memberno,this);
		this.status_set(status); //ajax succ
		//this.status_set(null);//ajax Fail
		return false;
	},
	status_cleared:function()
	{
		this.status_text='';
		ge('status_text').innerHTML='';
		this.hide();ge('status_blank_nag').innerHTML='Your status has been cleared.';
		setTimeout(function(){ge('status_blank_nag').innerHTML='Update your status...';}.bind(this),2500);
	},
	submit_status_clear:function()
	{
		this.status_blur=false;
		requestByGET("",memberno,this);
		this.status_cleared();//ajax succ and  Fail
		return false;
	},
	handle_key_press:function(event)
	{
		event=event||window.event;
		key_code=event.keyCode||event.which;
		if(key_code==KEYS.RETURN)
		{
			if(ge('edit_status_text').value!='')
				this.submit_status_set(ge('edit_status_text').value);
			return false;
		}
		if(key_code==KEYS.ESC){this.hide();return false;}
		return true;
	}
}
function requestByGET(status,memberno,obj)
{
    var a=status;
   status=EncodeMessage(status);
    WebServices.My.UpdateOnlineStatus(memberno,status);

}
 if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();
